package com.newlink.building.userinfo.mvp

import com.newlink.building.common_base.base.BasePresenter
import com.newlink.building.common_base.ext.doNext
import com.newlink.building.common_base.ext.ss
import com.newlink.building.common_base.utils.logDebug
import com.newlink.building.userinfo.mvp.contract.Module_UserInfo_FamilyManagementContract
import com.newlink.building.userinfo.mvp.model.Module_UserInfo_FamilyManagementModel

/**
 * @author wangyang
 * @date 2022/9/16
 * @description 我的——家庭管理页面的Presenter
 */
class Module_UserInfo_FamilyManagementPresenter :
    BasePresenter<Module_UserInfo_FamilyManagementContract.Model, Module_UserInfo_FamilyManagementContract.View>(),
    Module_UserInfo_FamilyManagementContract.Presenter {

    override fun createModel(): Module_UserInfo_FamilyManagementContract.Model? {
        return Module_UserInfo_FamilyManagementModel()
    }

    override fun getFamilyManagementList(
        token: String,
        page: Int,
        limit: Int,
    ) {
        mView?.showLoading()
        mModel?.getFamilyManagementList(token, page, limit)?.ss(mModel, mView) { result ->
            if (result?.data == null) {
                mView?.getFamilyManagementListFail()
            } else {
                val familyList = result?.data!!.list
                logDebug<Module_UserInfo_FamilyManagementPresenter>("getFamilyManagementList response list ->  $familyList")
                familyList.let {
                    mView?.getFamilyManagementListSuccess(it)
                }
            }
        }
    }

    override fun getFamilyMaxMemberCount(token: String, masterUserId: Long, prjType: Int) {

        mModel?.getFamilyMaxMemberCount(token, masterUserId, prjType)?.doNext { result ->
            if (result.code == 500) {
                mView?.getFamilyMaxMemberCountFail()
            } else {
                val maxCount = result.data
                logDebug<Module_UserInfo_FamilyManagementPresenter>("getFamilyManagementList response list ->  $maxCount")
                mView?.getFamilyMaxMemberCountSuccess(maxCount)
            }
        }
    }

}